import {
  Table,
  Row,
  Col,
  Form,
  Input,
  Icon,
  InputNumber,
  Radio,
  DatePicker,
  Select,
  Upload,
  Button,
  Switch,
  Modal,
  Popconfirm,
  Tabs,
  message,
  Steps,
  Card,
  Tag,
} from 'antd';

import { FormComponentProps } from 'antd/es/form';
import React from 'react';
import SingleDragger from '../../../../../components/Commons/SingleDragger';
import { connect } from 'dva';
import Constants from '@/utils/Constants';
import Validator from '@/utils/Validator';
import CstForm from '../components/CstForm';

const R = require('ramda');
const FormItem = Form.Item;
const RadioGroup = Radio.Group;
const TabPane = Tabs.TabPane;

const contractForm = Form.create()(
  class Contract extends React.Component {
    constructor(props) {
      super(props);
      this.state = {
        open: false,
      };
    }

    handleConfirm = () => {
      this.props.form.validateFields((errors, values) => {
        if (errors) return;

        let data = R.isNil(this.props.data) || R.isEmpty(this.props.data) ? {} : this.props.data;
        values.id = data.id;
        let props = this.props;

        this.props.dispatch({
          type: 'manageEnterpriseMyEnterprise/approval',
          payload: {
            ...values,
            onSuccess: () => {
              props.refreshData();
            },
          },
        });
        this.handleCancel();
      });
    };

    handleOpen = () => {
      this.setState({ open: true });
    };

    handleCancel = () => {
      this.props.form.resetFields();
      this.setState({ open: false });
    };

    render() {
      const { getFieldDecorator } = this.props.form;
      const formItemLayout = { labelCol: { sm: { span: 8 } }, wrapperCol: { sm: { span: 14 } } };

      let data = R.isNil(this.props.data) || R.isEmpty(this.props.data) ? {} : this.props.data;

      let footer = [];
      footer.push(
        <Button key="cancel" size="large" onClick={this.handleCancel.bind(this)}>
          取消
        </Button>,
      );
      footer.push(
        <Button key="primary" size="large" onClick={this.handleConfirm.bind(this)}>
          签约
        </Button>,
      );

      return (
        <Modal
          destroyOnClose
          title="企业签约"
          visible={this.state.open}
          width={900}
          footer={footer}
          onCancel={() => this.handleCancel.bind(this)()}
        >
          <CstForm parent={this.props} data={data} disabledStatus={true} />
        </Modal>
      );
    }
  },
);

function mapStateToProps(state) {
  return {
    loading: state.loading.models.contract,
  };
}

export default connect(mapStateToProps)(contractForm);
